package com.ftg.shopping.sp_deptinfo.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.shopping.config.LayuiPage;
import com.ftg.shopping.sp_deptinfo.entity.Sp_deptinfo;
import com.ftg.shopping.sp_deptinfo.mapper.Sp_deptinfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service
public class Sp_deptinfoService {

    @Autowired
    Sp_deptinfoMapper sp_deptinfoMapper;

    public int updateSp_deptinfo(Sp_deptinfo d) {
        return sp_deptinfoMapper.updateById(d);
    }


    public List<Sp_deptinfo> list() {
        return sp_deptinfoMapper.selectList(null);
    }

    public Sp_deptinfo findone(int deptno) {
        return sp_deptinfoMapper.selectById(deptno);
    }

    public IPage<Sp_deptinfo> testPage1(int page, int limit, String deptno) {
        IPage<Sp_deptinfo> ip = new Page<>(page, limit);
        QueryWrapper qw = new QueryWrapper();
        qw.like("deptno", deptno);
        return sp_deptinfoMapper.selectPage(ip, deptno == null || deptno.equals("") ? null : qw);
    }

    public int insert(Sp_deptinfo d) {
        return sp_deptinfoMapper.insert(d);
    }


    public int del1(int deptno) {
        return sp_deptinfoMapper.deleteById(deptno);
    }

    public LayuiPage<Sp_deptinfo> testpage2(int page, int limit) {

        IPage<Sp_deptinfo> ip = new Page<>(page, limit);
        sp_deptinfoMapper.selectPage(ip, null);
        return new LayuiPage<>(ip);
    }

    public LayuiPage<Sp_deptinfo> layuipage(@RequestParam int page, @RequestParam int limit, @RequestParam String dname) {
        IPage<Sp_deptinfo> ip = new Page<>(page, limit);
        QueryWrapper qw = new QueryWrapper();
        qw.like("dname", dname);
        sp_deptinfoMapper.selectPage(ip, dname == null || dname.equals("") ? null : qw);
        return new LayuiPage<>(ip);

    }
}